package com.action.book;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.controller.Action;
import com.dao.BookDao;
import com.domain.Book;

public class BookDeleteFormAction implements Action{
	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("euc-kr");
		
		HttpSession session = request.getSession();
		String mem_id = (String)session.getAttribute("mem_id");
		if(!mem_id.equals("admin")){
			return "/view/member/loginForm.jsp";
		}
		
		String select_book = request.getParameter("select_book");
		String num_name = request.getParameter("num_name");
		
		BookDao dao = BookDao.getinstance();
		Book book = new Book();
		
		if(select_book.equals("book_num")){
			
			try{
				int book_num = Integer.parseInt(num_name);
				book = dao.getBookByNum(book_num);
			} catch(NumberFormatException e){
				return "/view/book/bookDeleteForm.jsp";
			}
		} else if(select_book.equals("book_name")){
			book = dao.getBookByName(num_name);
		}
		
		request.setAttribute("book", book);
		return "/view/book/bookDeleteForm.jsp";
	}
}
